# -*- coding: utf-8 -*-
"""
@Time ： 2025/3/21 13:57
@Auth ： 刘佳
@File ：CheckVersionThread.py
@IDE ：PyCharm
@Motto:检查软件版本
"""
from PyQt5.QtCore import QThread, pyqtSignal
import pymysql

class CheckVersionThread(QThread):
    version_checked = pyqtSignal(str, str, str)  # 发送版本号、新版本公告、BotURL

    def __init__(self, dburl, parent=None):
        super(CheckVersionThread, self).__init__(parent)
        self.dburl = dburl

    def run(self):
        try:
            connection = pymysql.connect(
                host=self.dburl,
                user='root',
                password='123',
                database='ecadb'
            )
            cursor = connection.cursor()

            sql_query = """
                SELECT `key`, `value`
                FROM ecapp_siteconfig 
                WHERE `key` in ('BotURL', 'AutoGetVersion', 'AutoGETNotice')
            """
            cursor.execute(sql_query)
            res = {key: value for key, value in cursor.fetchall()}  # 转换为字典

            cursor.close()
            connection.close()

            bot_url = res.get('BotURL', '')
            version = res.get('AutoGetVersion', '')
            notice = res.get('AutoGETNotice', '')

            self.version_checked.emit(version, notice, bot_url)  # 发送信号

        except Exception as e:
            print(f"数据库查询失败: {e}")

